import * as actionTypes from '../actions/ActionTypes';

import { handleActions } from 'redux-actions';

//登录state
const LoginData = {
    msg:'',
    isloading:false//是否等待
}


export const loginEmailReducer = handleActions({
    [actionTypes.LOGIN_USER_EMAIL]: {
        next(state, action) {
            return { ret: true, statusText:'ok' , data: action.payload };
        },
        throw(state, action) {
            return { ret: false, statusText: 'err', data: LoginData };
        }
    }
}, { ret: true, statusText: 'def', data: LoginData });

//登录state
const LoginData2 = {
    msg:'',
    isloading:false//是否等待
}

export const loginPhoneReducer = handleActions({
    [actionTypes.LOGIN_USER_PHONE]: {
        next(state, action) {
            return { ret: true, statusText:'ok' , data: action.payload };
        },
        throw(state, action) {
            return { ret: false, statusText: 'err', data: LoginData2 };
        }
    }
}, { ret: true, statusText: 'def', data: LoginData2 });

const sendData = {
    msg:'',
    sendMsg:{}
}
export const sendCodeReducer = handleActions({
    [actionTypes.LOGIN_SEND_CODE]: {
        next(state, action) {
            return { ret: true, statusText:'ok' , data: action.payload };
        },
        throw(state, action) {
            return { ret: false, statusText: 'err', data: sendData };
        }
    }
}, { ret: true, statusText: 'def', data: sendData });

const tokenData = {
    msg:''
}

export const loginTokenReducer = handleActions({
    [actionTypes.LOGIN_USER_TOKEN]: {
        next(state, action) {
            return { ret: true, statusText:'ok' , data: action.payload };
        },
        throw(state, action) {
            return { ret: false, statusText: 'err', data: tokenData };
        }
    }
}, { ret: true, statusText: 'def', data: tokenData });